home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 April / Macworld (1999-04).dmg / Shareware World / Comms & Internet / PageSpinner 2.1 / PageSpinner 2.1 68K / Examples / JavaScript / Todays Link Example < prev    next >
Text File  |  1997-10-09  |  3KB  |  117 lines

  1. <HTML><HEAD>
  2. <TITLE>JavaScript Today's Link</TITLE>
  3.  
  4. <SCRIPT LANGUAGE="JavaScript">
  5. <!-- Beginning of JavaScript 
  6. /* 
  7.     Todays Link
  8.     Written by Jerry Aman, Optima System, July 28, 1996.
  9.     Part of the PageSpinner distribution.
  10.     
  11.     Updated October 9, 1997.
  12.     We will not be held responsible for any unwanted 
  13.     effects due to the usage of this script or any derivative.  
  14.     No warrantees for usability for any specific application 
  15.     are given or implied.
  16.  
  17.     You are free to use and modify this script,
  18.     if all credits are kept in the source code
  19. */
  20.  
  21.  
  22. function GetTodaysURL()
  23. {
  24.     // Put relative or full URL's in the strings below
  25.     // First line is returned on Mondays, second on Tuesdays ... 
  26.     // ... and the seventh on Sundays
  27.  
  28. var locationlist = new URLList 
  29. (
  30.     "groucho.html",        // Monday
  31.     "harpo.html",        // Tuesday
  32.     "zeppo.html",            
  33.     "chico.html",            
  34.     "harpo.html",            
  35.     "groucho.html",
  36.     "chico.html"        // Sunday
  37. );
  38.  
  39.     now = new Date();
  40.  
  41.     num = now.getDay();
  42.         if (num == 0)
  43.             num = 7;
  44.  
  45.     location.href = locationlist.list[num-1];
  46.  
  47. }
  48.  
  49. function URLList ()
  50. {
  51.     var argv = URLList.arguments;
  52.     var argc = argv.length;
  53.     this.list = new Object();
  54.     for (var i = 0; i < argc; i++)
  55.     this.list[i] = argv[i];
  56.     this.count = argc;
  57.     return this;
  58. }
  59.  
  60. // -- End of JavaScript code -------------- -->
  61. </SCRIPT>
  62.  
  63. </HEAD>
  64. <BODY BGCOLOR=FFFFFF TEXT=000000>
  65. <H1>JavaScript Today's Link</H1>
  66.  
  67. <B>This page contains a JavaScript that selects a different URL for each day of the
  68. week</B>
  69. <P>
  70. Please note that JavaScript is currently only available in Netscape Navigator 2.0 or later, and in Internet Explorer for MacOS version 3.0.1 or later. <FONT COLOR="931B15">Do not assume that all in your audience are using a JavaScript enabled browser.</FONT>
  71. <HR>
  72. <P>
  73. This JavaScript lets you present a different link to a different document URL for each day of the week. 
  74.  
  75. <P>
  76. You can use this to direct your readers to a different site each day of the week, or if you run a daily newsletter you can use it to let readers to go to a specific file depending on the day of the week.
  77.  
  78. <P>
  79. The script is named <B>GetTodaysURL</B> and it is placed in the HEAD section of the HTML document. The script is executed by clicking on a link containing a call to GetTodaysURL(). Also note the <FONT COLOR="FF3366">custom text</FONT> in Netscape's status area.
  80.  
  81. <P>
  82. Example of this script picking  
  83. <A HREF="javascript:GetTodaysURL()"
  84.  onMouseOver="window.status='This link takes you the page of the day!'; return true">todays</A> page. Another page will be displayed tomorrow.
  85.  
  86.  
  87. <P>
  88. <B>How to use:</B><BR>
  89. Replace the filenames inside the script with your own URLs and edit this page contents inside the <BODY> section. (You can also copy the entire script to one of your existing pages).
  90.  
  91. <P>
  92. <PRE>function GetTodaysURL()
  93. {
  94.     // Put relative or full URL's in the strings below
  95.     // First line is returned on Mondays, second on Tuesdays ... 
  96.     // ... and the seventh on Sundays
  97.  
  98. var locationlist = new URLList 
  99. (
  100.     "groucho.html",        // Monday
  101.     "harpo.html",        // Tuesday
  102.     "zeppo.html",            
  103.     "chico.html",            
  104.     "harpo.html",            
  105.     "groucho.html",
  106.     "chico.html"        // Sunday
  107. );</PRE>
  108.  
  109. <P>
  110. Use code similar to this to let the user execute the script:
  111. <P>
  112. <PRE><A HREF="javascript:GetTodaysURL()"
  113.  onMouseOver="window.status='This link takes you the page of the day!'; return true">Todays page</A></PRE>
  114.  
  115. </BODY>
  116. </HTML>
  117.